package com.itheima.hello.TCP通信.群聊端口转发;

import java.io.DataInputStream;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

public class Server1 {
    public static List<Socket> onLineSocket = new ArrayList<>();//用来存储在线的客户端
    public static void main(String[] args) throws Exception {
        System.out.println("<北极熊群聊>服务端启动成功");
        System.out.println("---------------------------------");
        //创建ServerSocket对象,同时为服务端注册端口号
        ServerSocket serverSocket = new ServerSocket(8080);

        while (true) {
            //使用ServerSocket对象，调用一个accept方法。等待客户端的连接请求
            Socket socket = serverSocket.accept();
            onLineSocket.add(socket);
            System.out.println(LocalDateTime.now() + ":");
            System.out.println("有人上线了:" + socket.getRemoteSocketAddress());
            System.out.println("---------------------------------");
            new ServerReaderThread(socket).start();

        }

    }
    }

